package qjc.j_回溯;

import java.util.ArrayList;
import java.util.List;

public class j2_子集 {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<List<Integer>>();
        List<Integer> output = new ArrayList<>();
        int start = 0;
        backtrack(res, output, nums, start);
        return res;
    }

    private void backtrack(List<List<Integer>> res, List<Integer> output, int[] nums,int start) {
        res.add(new ArrayList<>(output));
        for (int i = start; i < nums.length; i++) {
            output.add(nums[i]);
            backtrack(res, output, nums, i + 1);
            output.remove(output.size() - 1);
        }
    }
}
